package com.akeil.flash.dialog;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class QueryConditionDialog extends TitleAreaDialog {
	private Text textSamplename;
	private Text textSampleno;
	private String start,end;
	private String sampleName;
	private String sampleNo;
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	private DateTime dateTimeStart;
	private DateTime dateTimeEnd;
	Calendar calendar = Calendar.getInstance();
	
	public QueryConditionDialog(Shell parentShell) {
		super(parentShell);
		// TODO Auto-generated constructor stub
	}

	protected Control createDialogArea(Composite parent) {
		Composite composite = (Composite) super.createDialogArea(parent);
		
		Composite composite_1 = new Composite(composite, SWT.NONE);
		composite_1.setLayout(new FormLayout());
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Label lblNewLabel = new Label(composite_1, SWT.NONE);
		FormData fd_lblNewLabel = new FormData();
		fd_lblNewLabel.left = new FormAttachment(0, 10);
		lblNewLabel.setLayoutData(fd_lblNewLabel);
		lblNewLabel.setText("分析日期");
		
		dateTimeStart = new DateTime(composite_1, SWT.BORDER | SWT.DROP_DOWN);
		fd_lblNewLabel.top = new FormAttachment(0, 10);
		FormData fd_dateTimeStart = new FormData();
		fd_dateTimeStart.top = new FormAttachment(0, 6);
		fd_dateTimeStart.left = new FormAttachment(lblNewLabel, 21);
		dateTimeStart.setLayoutData(fd_dateTimeStart);
		
		dateTimeEnd = new DateTime(composite_1, SWT.BORDER | SWT.DROP_DOWN);
		FormData fd_dateTimeEnd = new FormData();
		fd_dateTimeEnd.top = new FormAttachment(0, 6);
		fd_dateTimeEnd.right = new FormAttachment(100, -77);
		dateTimeEnd.setLayoutData(fd_dateTimeEnd);
		
		Label lblNewLabel_1 = new Label(composite_1, SWT.NONE);
		FormData fd_lblNewLabel_1 = new FormData();
		fd_lblNewLabel_1.top = new FormAttachment(lblNewLabel, 27);
		fd_lblNewLabel_1.left = new FormAttachment(lblNewLabel, 0, SWT.LEFT);
		lblNewLabel_1.setLayoutData(fd_lblNewLabel_1);
		lblNewLabel_1.setText("样品名称");
		
		textSamplename = new Text(composite_1, SWT.BORDER);
		FormData fd_textSamplename = new FormData();
		fd_textSamplename.top = new FormAttachment(lblNewLabel_1, -3, SWT.TOP);
		fd_textSamplename.left = new FormAttachment(dateTimeStart, 0, SWT.LEFT);
		fd_textSamplename.right = new FormAttachment(dateTimeEnd, 0, SWT.RIGHT);
		textSamplename.setLayoutData(fd_textSamplename);
		
		Label label = new Label(composite_1, SWT.NONE);
		label.setText("样品编号");
		FormData fd_label = new FormData();
		fd_label.top = new FormAttachment(lblNewLabel_1, 25);
		fd_label.left = new FormAttachment(lblNewLabel, 0, SWT.LEFT);
		label.setLayoutData(fd_label);
		
		textSampleno = new Text(composite_1, SWT.BORDER);
		FormData fd_textSmapleno = new FormData();
		fd_textSmapleno.right = new FormAttachment(dateTimeEnd, 0, SWT.RIGHT);
		fd_textSmapleno.top = new FormAttachment(textSamplename, 16);
		fd_textSmapleno.left = new FormAttachment(dateTimeStart, 0, SWT.LEFT);
		textSampleno.setLayoutData(fd_textSmapleno);
		
		this.setTitle("设置查询结果条件");
		//this.setMessage("请正确输入Lims参数值",IMessageProvider.INFORMATION);
		
		initTextData();
		return composite;
	}
	
	private void initTextData(){
	}

	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("查询参数");
	}
	
	@Override
	public void setErrorMessage(String newErrorMessage) {
		// TODO Auto-generated method stub
		Button okButton = getButton(IDialogConstants.OK_ID);
        if (okButton != null) 
            okButton.setEnabled(newErrorMessage == null);
        
		super.setErrorMessage(newErrorMessage);
	}

	@Override
	protected void okPressed() {
		// TODO 自动生成的方法存根
		calendar.set(dateTimeStart.getYear(), dateTimeStart.getMonth(), dateTimeStart.getDay(), 0, 0, 0);
		start = sdf.format(calendar.getTime());
		
		calendar.set(dateTimeEnd.getYear(), dateTimeEnd.getMonth(), dateTimeEnd.getDay(), 23, 59, 59);
		end = sdf.format(calendar.getTime());
		sampleName = textSamplename.getText().trim();
		sampleNo = textSampleno.getText().trim();
		
		super.okPressed();
	}

	public String getStart() {
		return start;
	}

	public void setStart(String start) {
		this.start = start;
	}

	public String getEnd() {
		return end;
	}

	public void setEnd(String end) {
		this.end = end;
	}

	public String getSampleName() {
		return sampleName;
	}

	public void setSampleName(String sampleName) {
		this.sampleName = sampleName;
	}

	public String getSampleNo() {
		return sampleNo;
	}

	public void setSampleNo(String sampleNo) {
		this.sampleNo = sampleNo;
	}
	

}
